package com.example.module_word.fragment

import android.content.Intent
import android.os.Handler
import android.view.View
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.compose.LifecycleResumeEffect
import com.example.module_word.activity.CameraActivity
import com.example.module_word.activity.DanCiActivity
import com.example.module_word.activity.IndexStackActivity
import com.example.module_word.activity.LexiconActivity
import com.example.module_word.activity.PlanActivity
import com.example.module_word.databinding.FragmentPlanBinding
import com.example.module_word.util.TimeUtils
import com.example.module_word.viewmodel.HomeViewModel
import com.example.module_word.viewmodel.PlanViewModel
import com.fenghuajueli.libbasecoreui.utils.AdUtil
import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModelFragment2
import com.ll.permission.AllowPermissionUseCase

class PlanFragment:BaseViewModelFragment2<PlanViewModel,FragmentPlanBinding>() {

    var vm = HomeViewModel()

    override fun createViewModel(): PlanViewModel {
        return PlanViewModel()
    }

    override fun createViewBinding(): FragmentPlanBinding {
        return FragmentPlanBinding.inflate(layoutInflater)
    }

    fun refresh(){
        if (vm != null){
            vm.refreshTheData()
        }
    }
    override fun initView(p0: View?) {
        refresh()
        binding.tvDate.text = TimeUtils.getCurrentDate() + "  "+TimeUtils.getCurrentWeek()
        binding.ivZdjh.setOnClickListener {
            requireContext().startActivity(
                Intent(context, PlanActivity::class.java).putExtra(
                    "kind",
                    vm.currentKind.value
                )
            )
        }
        binding.tvBdc.setOnClickListener {
            if (vm.wordOfTheDay.value == "0") {
                requireContext().startActivity(
                    Intent(context, PlanActivity::class.java).putExtra(
                        "kind",
                        vm.currentKind.value
                    )
                )
            } else {
                requireContext().startActivity(
                    Intent(context, DanCiActivity::class.java).putExtra(
                        "kind",
                        vm.currentKind.value
                    ).putExtra(
                        "jrdc",
                        vm.wordOfTheDay.value
                    )
                )
            }
        }
        binding.ivAbc.setOnClickListener {
            requireContext().startActivity(
                Intent(context, LexiconActivity::class.java).putExtra(
                    "kind",
                    vm.currentKind.value
                ).putExtra(
                    "jrdc",
                    vm.wordOfTheDay.value
                )
            )
        }
        binding.ivQh.setOnClickListener {
            requireContext().startActivity(Intent(context, IndexStackActivity::class.java))
        }

        binding.tvJrdc.text = vm.wordOfTheDay1
        binding.tvSydc.text = vm.remainingWords1
        binding.tvSyts.text = vm.numberOfDaysRemaining1
        binding.tvDk.text = "打卡"+vm.numberOfPunches1+"次"
    }

    override fun initData() {

    }

    override fun onResume() {
        super.onResume()
        refresh()
        Handler().postDelayed(Runnable {
            binding.tvJrdc.text = vm.wordOfTheDay1
            binding.tvSydc.text = vm.remainingWords1
            binding.tvSyts.text = vm.numberOfDaysRemaining1
            binding.tvDk.text = "打卡"+vm.numberOfPunches1+"次"
        },100)


    }
}